package de.nabble.model;

import java.util.Arrays;


public class LetterRow {
	private static int LETTER_COUNT = 7;
	
	private Letter[] letters;
	private LetterBag bag;
	
	public LetterRow(LetterBag bag) {
		this.bag = bag;
		letters = new Letter[LETTER_COUNT];
		fill();
	}
	
	public void fill() {
		for(int i = 0; i < letters.length; i++) {
			if(letters[i] == null) {
				letters[i] = bag.takeLetter();
			}
		}
	}
	
	public void removeLetter(int index) {
		letters[index] = null;
	}
	
	public Letter[] getLetters() {
		return letters;
	}
	
	public boolean containsLetter(Letter l) {
		for(Letter m : letters) {
			if(m.equals(l))
				return true;
		}
		return false;
	}
	
	@Override
	public String toString() {
		return Arrays.toString(letters);
	}

	public void putOne(Letter l) {
		for(int i = 0; i < letters.length; i++) {
			if(letters[i] == null) {
				letters[i] = l;
				return;
			}
		}		
	}
}
